package com.yjhb.android.sbz.mvp.userinfo;

import com.yjhb.android.sbz.entity.ShopInfo;
import com.yjhb.android.sbz.entity.UserFollow;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

/**
 * 创建者 zx
 * 创建时间 2021/1/8 11:58
 */
public class UserInfoPresenter extends ConventionPresenter<UserInfoView> {
    private final String TAG = "UserInfoPresenter";

    public UserInfoPresenter(UserInfoView userInfoView) {
        super(userInfoView);
    }

    @Override
    protected void onDestroy() {

    }


    public void getUserInfo(Integer userId) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.getUser(userId), new HttpObserver<UserFollow>() {
            @Override
            public void onResult(UserFollow data) {
                if (view != null) {
                    view.onSuccess(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


    /**
     * @param userId
     * @param type   1、关注；2、取消关注
     */
    public void follow(Integer userId, int type) {
        if (view != null) {
            view.onWait();
        }
        HttpTool.request(model.follow(userId, type), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view != null) {
                    view.onFollow();
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }


    /**
     * 获取用户行为
     */
    public void getUserBehavior(Integer userId) {
        HttpTool.request(model.getShopInfo(userId), new HttpObserver<ShopInfo>() {
            @Override
            public void onResult(ShopInfo data) {
                if (view != null) {
                    view.onShopInfo(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

}
